package com.ghy.springbootsentinel;

import com.alibaba.csp.sentinel.cluster.ClusterStateManager;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class SpringbootSentinelApplication {

    public static void main(String[] args) {
        //设置应用状态,表示是客户端
        ClusterStateManager.applyState(ClusterStateManager.CLUSTER_CLIENT);
//        initFlowRule();
        SpringApplication.run ( SpringbootSentinelApplication.class ,args );
    }

   //声明限流规则
    private static void initFlowRule(){
        List<FlowRule> rules=new ArrayList<> ();
        FlowRule flowRule=new FlowRule();
        flowRule.setResource("doTest"); //针对那个资源设置规则
        flowRule.setGrade( RuleConstant.FLOW_GRADE_QPS);//QPS或者并发数
        flowRule.setCount(5); //QPS=5
        rules.add(flowRule);
        FlowRuleManager.loadRules(rules);
    }
}
